use ggez::{glam::Vec2,Context, graphics, mint::Point2};

use crate::animation::Animation;

pub struct Baton {
    location: Vec2,
    angle: Vec2,
    velocity: Vec2,
    amplitude: Vec2,
    acceleration: Vec2
}

impl Baton {
    pub fn new(location: Vec2, angle: Vec2, velocity: Vec2, amplitude: Vec2) -> Baton {
        let acceleration = Vec2{x: 0.00001, y: 0.0005};
        Baton {location, angle, velocity, amplitude, acceleration}
    }

}

impl Animation for Baton {
    fn update(&mut self, _ctx: &mut Context) -> () {
        self.velocity+=self.acceleration;
        self.angle+=self.velocity;
    }

    fn display(&self, ctx: &mut Context, canvas : &mut graphics::Canvas) -> () {
        let x = self.angle.x.sin()*self.amplitude.x;
        let y = self.angle.y.sin()*self.amplitude.y;

        let line = graphics::Mesh::new_line(
            ctx, 
            &[Point2{x: 0.0, y: 0.0}, Point2{x, y}], 
            2.0, 
            graphics::Color::BLACK
        ).unwrap();
        canvas.draw(&line, graphics::DrawParam::default().dest(self.location));
        

        let circle = graphics::Mesh::new_circle(
            ctx,
            graphics::DrawMode::fill(),
            Point2{x, y},
            16.0,
            0.1,
            graphics::Color { r: 0.7, g: 0.7, b: 0.7, a: 1.0 },
        ).unwrap();
        canvas.draw(&circle, graphics::DrawParam::default().dest(self.location));
        let circle = graphics::Mesh::new_circle(
            ctx,
            graphics::DrawMode::stroke(2.0),
            Point2{x, y},
            16.0,
            0.1,
            graphics::Color::BLACK,
        ).unwrap();
        canvas.draw(&circle, graphics::DrawParam::default().dest(self.location));

    }
}
